package org.richin.collection.util;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.apache.commons.beanutils.BeanComparator;

import com.sun.istack.internal.FinalArrayList;

public class ListSorter {

	public static <V> void sort(List<V> list, final String... properties) {
		Collections.sort(list, new Comparator<V>() {

			public int compare(V o1, V o2) {
				if (o1 == null && o2 == null)
					return 0;
				if(o1==null)return -1;
				if(o2==null) return 1;
				for(String property:properties)
				{
					Comparator<V> c=new BeanComparator(property);
					int result=c.compare(o1, o2);
					if (result!=0) {
						return result;
					}
				}
				return 0;
			}

		});
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
